package com.cuit.controller;

import com.cuit.pojo.Doctor;
import com.cuit.service.DoctorService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/personal")
public class d_personalServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Doctor d=new Doctor();
        Doctor d2=(Doctor)request.getSession().getAttribute("doc");
        d.setId(d2.getId());
        d.setName(request.getParameter("name"));
        d.setSex(request.getParameter("sex"));
        d.setAge(Integer.parseInt(request.getParameter("age")));
        d.setGrade(request.getParameter("grade"));
        d.setDepartment(request.getParameter("depart"));
        d.setProfile(request.getParameter("profile"));
        d.setPassword(request.getParameter("password"));
        DoctorService ds=new DoctorService(d);
        ds.upda();
        if(d.getName()!=null){
            d2.setName(d.getName());
        }
        if(d.getSex()!=null){
            d2.setSex(d.getSex());
        }
        if(d.getAge()!=0){
            d2.setAge(d.getAge());
        }
        if(d.getGrade()!=null){
            d2.setGrade(d.getGrade());
        }
        if(d.getDepartment()!=null){
            d2.setDepartment(d.getDepartment());
        }
        if(d.getProfile()!=null){
            d2.setProfile(d.getProfile());
        }
        if(d.getPassword()!=null){
            d2.setPassword(d.getPassword());
        }
        request.getSession().setAttribute("doc",d2);
        response.sendRedirect("/hospital/doctor_cm/personal_data/d_per.jsp");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
